<?php echo view('header.html');?>

<body class="layui-view-bodys">
    <div class="layui-form-iframe">
        <form class="layui-form layui-card-body" action="" id="myform" name="myform">

            <input name="data[pid]" type="hidden" value="<?=isset($data['pid']) ? $data['pid'] : 0?>">
            <input name="id" type="hidden" value="<?=isset($data['id']) ? $data['id'] : 0?>">

            <div class="layui-form-item">
                <label class="layui-form-label">上级菜单</label>
                <div class="layui-input-inline">
                    <select name="data[pid]">
                        <option value="0">顶级菜单</option>
                        <?php if(isset($top)):?>
                        <?php foreach($top as $k=>$v):?>
                        <option value="<?=$k?>" <?php if($k==$pid){echo 'selected';}?>><?=$v['name']?></option>
                        <?php endforeach;?>
                        <?php endif ?>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">菜单名称</label>
                <div class="layui-input-block">
                    <input type="text" name="data[name]" id="ams_name" value="<?=isset($data['name']) ? $data['name'] : ''?>" required lay-verify="required" placeholder="" autocomplete="off" class="layui-input">
                </div>
            </div>
            <?php if($pid):?>
            <div class="layui-form-item t_2">
                <label class="layui-form-label">菜单地址</label>
                <div class="layui-input-block">
                    <input type="text" name="data[uri]" id="ams_c" value="<?=isset($data['uri']) ? $data['uri'] : ''?>" lay-verify="required" autocomplete="off" class="layui-input">
                    <div class="layui-form-mid layui-word-aux">URI格式为：模块目录名/控制器名/方法名</div>
                </div>
            </div>
            <div class="layui-form-item t_2">
                <label class="layui-form-label">参数</label>
                <div class="layui-input-block">
                    <input type="text" name="data[param]" id="ams_param" value="<?=isset($data['param_str']) ? $data['param_str'] : ''?>" autocomplete="off" class="layui-input">
                    <div class="layui-form-mid layui-word-aux">格式：参数1=值&参数2=值..</div>
                </div>
            </div>
            <div class="layui-form-item t_2">
                <label class="layui-form-label">链接地址</label>
                <div class="layui-input-block">
                    <input type="text" name="data[url]" id="ams_url" value="<?=isset($data['url']) ? $data['url'] : ''?>" autocomplete="off" class="layui-input">
                    <div class="layui-form-mid layui-word-aux">指定一个URL地址</div>
                </div>
            </div>
            <?php endif ?>
            <div class="layui-form-item">
                <label class="layui-form-label">图标</label>
                <div class="layui-input-inline">
                    <input type="text" name="data[icon]" value="<?=isset($data['icon']) ? $data['icon'] : 'layui-icon '?>" lay-verify="required" placeholder="菜单图标" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux"><a href="<?=url('admin/home/icon')?>" target="_blank">查看更多图标</a></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">显示隐藏：</label>
                <div class="layui-input-inline">
                    <input type="radio" lay-filter="status" <?php if ((isset($data['show']) && $data['show']=='0')){echo 'checked';}?> name="data[show]" value="0" title="隐藏">
                    <input type="radio" lay-filter="status" <?php if (isset($data['show']) && $data['show']==1){echo 'checked';}?> name="data[show]" value="1" title="显示">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-blue" lay-submit lay-filter="menu_add">提交保存</button>
                </div>
            </div>
        </form>
    </div>
    <?php echo view('footer.html');?>
    <script type="text/javascript">

        layui.use(['layer', 'jquery', 'form'], function () {
            var form = layui.form,
                $ = layui.jquery,
                layer = layui.layer;

            form.on('submit(menu_add)', function (data) {
                var url = window.location.href;
                $.post(url, data.field, function (res) {
                    if (res.code == 0) {
                        layer.msg(res.msg, { icon: 1, time: 1000 }, function () {
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.location.href = adminpath + 'admin/menu/index';
                            parent.layer.close(index);
                        });
                    } else {
                        layer.msg(res.msg, { icon: 5, time: 1500, anim: 6 });
                    }
                }, 'json');
                return false;
            });
        });


    </script>
</body>

</html>